using Services;
using UnityEngine.Events;

public class SkillTreeUI_Manager : MyCanvasGrounp
{
    public UnityAction ContentChange;
    public Player Player { get; private set; }
    public SkillTreeManager Tree { get; private set; }
    public SkillTreeUI_SkillNode[] UINodes { get; private set; }

    protected override void Awake()
    {
        base.Awake();
        Tree = GetComponent<SkillTreeManager>();
        UINodes = GetComponentsInChildren<SkillTreeUI_SkillNode>();
    }

    private void Start()
    {
        Player = ServiceLocator.Get<ActionController>().player;
        EventSystem eventSystem = ServiceLocator.Get<EventSystem>();
        eventSystem.AddListener<EGameState, EGameState>(EEvent.GameStateChange, OnGameStateChange);
        immediate_next = true;
        Visible = false;
    }

    private void OnGameStateChange(EGameState from, EGameState to)
    {
        switch (to)
        {
            case EGameState.OpenSkillTree:
                Tree.MyReset();
                ContentChange?.Invoke();
                Visible = true;
                break;
            default:
                Visible = false;
                break;
        }
    }
}
